1 using UnityEngine;
2 using
System.Collections.Generic;
3
4 public
class Actor : MonoBehaviour {
5
6     
private List<Action> actions = new List<Action>(0);
7
8     
private bool isRunning;
9
10     
void Start () {
11         isRunning =
true;
12     }
13
14     
public void addAction(Action action)
15     {
16         action.setActor(
this);
17         actions.Add(action);
18     }
19     
20     
void Update () {
21         
if(isRunning)
22             Act(Time.deltaTime);
23     }
24
25     
public void Act(float delta)
26     {
27         
for (int i = 0; i < actions.Count; i++)
28         {
29             Action action = actions[i];
30             
if (action.Act(delta) && i < actions.Count)
31             {
32                 actions.RemoveAt(i);
33                 action.setActor(
null);
34                 i--;
35             }
36         }
37     }
38
39     
public int getActionCounter()
40     {
41         
return actions.Count;
42     }
43
44     
public void setRunning(bool isRunning)
45     {
46         
this.isRunning = isRunning;
47     }
48 }



Trò chơi đua xe động vật trong UNITY Engine 114.817 lượt xem

Gõ tìm kiếm nhanh...